<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane label="会议室看板" name="first">
        <el-date-picker
          v-model="time"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
        <div class="flex">
          <el-col :span="1">
            <div class="type" style="background: #909399;"></div>禁用
          </el-col>
          <el-col :span="1">
            <div class="type" style="background: #67c23a;"></div>可用
          </el-col>
          <el-col :span="1">
            <div class="type" style="background: red;"></div>占用
          </el-col>
        </div>
        <div class="timeList">
          <div class="subitem" v-for="item in timeList" :key="item">{{ item }}</div>
        </div>
        <div class="timeList" style="margin-left: 0;" v-for="item in meetList" :key="item">
          <div style="width: 100px;flex-shrink: 0;">{{ item }}</div>
          <div class="room" v-for="item in 16" :key="item"></div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="会议室管理" name="second">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
          <el-form-item label="会议室名称" prop="status">
            <el-select
              v-model="queryParams.status"
              placeholder="请选择"
              clearable
              style="width: 240px"
            >
              <el-option
                v-for="dict in dict.type.sys_normal_disable"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="最大使用人数">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="设备设施" prop="roleName">
            <el-input
              v-model="queryParams.roleName"
              placeholder="请输入"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item> 
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:role:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-view"
              size="mini"
              @click="handleExport"
              v-hasPermi="['system:role:export']"
            >查看</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              @click="handleUpdate"
              v-hasPermi="['system:role:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              @click="handleDelete"
              v-hasPermi="['system:role:remove']"
            >删除</el-button>
          </el-col>
        </el-row>

        <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序号" type="index" :index="indexMethod" width="80" />
          <el-table-column label="会议室名称" prop="roleName" />
          <el-table-column label="会议室编号" prop="roleKey" />
          <el-table-column label="会议室位置" prop="roleSort" />
          <el-table-column label="最大使用人数" prop="roleSort" />
          <el-table-column label="会议室使用时间" prop="roleSort"  />
          <el-table-column label="设备设施" prop="roleSort" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
            <template slot-scope="scope">
              <el-button
                type="text"
                icon="el-icon-view"
                size="mini"
                v-hasPermi="['finance:expenseControl:view']"
              >详情</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:role:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:role:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <pagination
        v-show="total>0&&activeName==='second'"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    <!-- 新增编辑弹窗 -->
    <el-dialog :title="title" :visible.sync="openDataScope" width="550px" append-to-body>
      <el-form ref="addForm" :rules="addRules" :model="addForm" label-width="110px">
        <el-form-item label="会议室名称" prop="q">
          <el-input v-model="addForm.q" />
        </el-form-item>
        <el-form-item label="会议室位置" prop="w">
          <el-input v-model="addForm.w" />
        </el-form-item>
        <el-form-item label="最大使用人数" prop="e">
          <el-input v-model="addForm.e" />
        </el-form-item>
        <el-form-item label="使用时间" prop="r">
          <el-date-picker
            v-model="addForm.r"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="设备设施" prop="t">
          <el-input v-model="addForm.t" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDataScope">确 定</el-button>
        <el-button @click="cancelDataScope">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { listRole, getRole, delRole } from "@/api/system/role";
export default {
  dicts: ['sys_normal_disable'],
  data() {
    return {
      meetList: ['3楼小会议室','大型会议室','中型会议室'],
      timeList: ['7:00','8:00','9:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00'],
      activeName: 'first',
      queryParams: {},
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined
      },
      time: '',
      // 选中数组
      ids: [],
      // 弹窗字段
      title: '新增会议室',
      openDataScope: false,
      addForm: {},
      addRules: {
        q: [{ required: true, message: '请输入', trigger: 'blur' }],
        w: [{ required: true, message: '请输入', trigger: 'blur' }],
        e: [
            { required: true, message: '请输入', trigger: 'blur' },
            {
              pattern: /^\d+$/,
              message: "请输入正确的最大使用人数",
              trigger: "blur"
            }
          ],
        r: [{ required: true, message: '请选择', trigger: 'change' }],
        t: [{ required: true, message: '请输入', trigger: 'blur' }]
      },
      openDetail: false, // 详情
    }
  },
  created() {
    this.getList();
  },
  methods: {
    // 表单重置
    reset() {
      this.addForm = {
        q: '',
        w: '',
        e: '',
        r: '',
        t: ''
      }
      this.resetForm("addForm");
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roleId);
    },
    // 序号计算
    indexMethod(index) {
      return (this.queryParams.pageNum- 1) * this.queryParams.pageSize + index + 1;
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.roleList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openDataScope = true;
      this.title = "新增会议室";
    },
    // 弹窗提交
    submitDataScope() {

    },
    // 查看按钮
    handleExport() {

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.title = "修改会议室";
      this.openDataScope = true;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.roleId || this.ids;
      this.$modal.confirm('是否确认删除角色编号为"' + roleIds + '"的数据项？').then(function() {
        return delRole(roleIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
}
</script>
<style scoped lang="scss">
.flex {
  align-items: center;
  justify-content: end;
  overflow: hidden;
  display: flex;
  font-size: 12px;
  .el-col {
    display: flex;
    align-items: center;
    .type {
      width: 20px;
      height: 20px;
      border-radius: 5px;
      margin-right: 4px;
    }
  }
}
.timeList {
  display: flex;
  margin: 20px 0 0 100px;
  color: #666;
  .subitem {
    flex-shrink: 0;
    width: 40px;
    margin: 15px;
  }
}
.room {
  width: 30px;
  height: 30px;
  background: #909399;
  border-radius: 5px;
  margin-left: 40px;
  flex-shrink: 0;
  &:nth-child(2) {
    margin-left: 55px;
  }
}
</style>